program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  n, i,j,s,t,sum: integer;
  mass : array of integer;
begin
  readln(n);
  setlength(mass, n);
  for i:=0 to n-1 do
    read(mass[i]);
  for j:=0 to n-1 do
  begin
    s:=j;
    for i:=j+1 to n-1 do
    begin
      if (mass[i]>= mass[s]) then
        s:=i;
    end;
    t:=mass[j];
    mass[j]:= mass[s];
    mass[s]:= t;
  end;
  sum:=mass[0]+ mass[n-1];
  writeln(sum);
  readln;
  readln;

end.
